/*
 * BlocksNumCache.h
 *
 *  Created on: Jun 11, 2010
 *      Author: Lukasz Spintzyk
 */

#ifndef BLOCKSNUMCACHE_H_
#define BLOCKSNUMCACHE_H_

#ifndef INODE_H_
#include "Inode.h"
#endif

class InodeManager;
class BlockManager;

class BlocksNumCache {
public:
	BlocksNumCache(InodePtr fileInode,
	    	 InodeManager& inodeMgr,
	    	 BlockManager& blockMgr);
	~BlocksNumCache();
	BlocksNumCache(const BlocksNumCache& cache);

    uint32_t cachedBlkIndex2Num(uint32_t block_index);

protected:
    void updateBlocksCacheIfNeeded(uint32_t block_num);
    bool blockNumNotCached(uint32_t blockNum);
    void updateCache(uint32_t block_num);
    uint32_t rewindEndCache(uint32_t rel_pos);

private:

    InodePtr d_fileInode;
	InodeManager& d_inodeMgr;
	BlockManager& d_blockMgr;
	uint32_t* d_blocksCache;
    uint32_t d_startCache;
    uint32_t d_endCache;
};

#endif /* BLOCKSNUMCACHE_H_ */
